export function useReg() {
  //用户名规则校验
  const validateUser = (rule: any, value: any, callback: any) => {
    if (value.trim().length == 0) {
      callback(new Error("用户名不能为空"));
    } else {
      callback();
    }
  };

  //密码规则校验
  const validatePass = (rule: any, value: any, callback: any) => {
    if (value.trim().length < 6) {
      callback(new Error("密码不少于6位！"));
    } else {
      callback();
    }
  };

  //性别规则校验
  const validateSex = (rule: any, value: any, callback: any) => {
    if (!value) {
      callback(new Error("请选择"));
    } else {
      callback();
    }
  };

  //出生日期规则校验
  const validateBir = (rule: any, value: any, callback: any) => {
    if (!value) {
      callback(new Error("请输入出生日期"));
    } else {
      callback();
    }
  };

  //手机号码规则校验
  const validatePhone = (rule: any, value: any, callback: any) => {
    const Reg =
      /^1((34[0-8])|(8\d{2})|(([35][0-35-9]|4[579]|66|7[35678]|9[1389])\d{1}))\d{7}$/;
    if (!Reg.test(value.trim())) {
      callback(new Error("请输入有效的手机号码"));
    } else {
      callback();
    }
  };

  //地址规则校验
  const validateAddress = (rule: any, value: any, callback: any) => {
    // const Reg =
    //   /^(?<province>[^省]+省|.+自治区)(?<city>[^自治州]+自治州|[^市]+市|[^盟]+盟|[^地区]+地区|.+区划)(?<county>[^市]+市|[^县]+县|[^旗]+旗|.+区)?(?<town>[^区]+区|.+镇)?(?<village>.*)$/;
    if (value.trim().length == 0) {
      callback(new Error("请输入有效地址"));
    } else {
      callback();
    }
  };

  return {
    validateUser,
    validatePass,
    validateSex,
    validateBir,
    validatePhone,
    validateAddress,
  };
}
